<template>
	<view>	
		<view class="location"></view>
		<view class='add_location' @tap="add_location">新增地址</view>
		<view class="cart-box">
		    <view class="cart-item" v-for="(item,index) in list" :key="index">
		      <view class="cart-item-main">
		        <view class="cart-item-word">
		            <view class="title-box">
		              <text>联系人：{{item.name}}</text>
		              <text>联系电话：{{item.phone}}</text>
		            </view> 
		            <view class="title-box">
		              <text>地址：{{item.province_name}}，{{item.city_name}}，{{item.county_name}}，{{item.detailed_address}}</text>
		            </view>
		            <view class="operation">
		                <view class="operation-status" v-if="item.status==1">默认</view>
						<view class="operation-edit" @tap="edit_location" :data-id="item.id">编辑</view>
						<view class="operation-delete" @tap="delete_site" :data-index="index">删除</view>
		            </view> 
		        </view>
		      </view>
		    </view>
		</view>
	</view>
</template>
<script>
	import Location from './location-model.js'
	var location = new Location(); 
	export default {
		data() {
			return {
				list:[],
			}
		},
		onShow(){
			this.site_list();
		},
		methods: {
			add_location(){
				location.navigate_to('../add_location/add_location');
			},
			edit_location(e){
				var id = location.get_data_set(e,'id');
				location.navigate_to('../edit_location/edit_location?id='+id);
			},
			delete_site(e){
				var that = this;
				location.show_modal({content:'确定要删除地址吗！'},(res)=>{
					if (res.confirm) {
						var index = location.get_data_set(e,'index');
						location.delete_site(that.list[index].id,(res)=>{
							if(res.code == 8888){
								that.list = location.delete_arr_index(that.list,index);
							}
						})
					}	
				})
			},
			site_list(){
				var that = this;
				location.site_list((res)=>{
					if(res.code == 8888){
						that.list = res.data;
					}
				})
			}
		}
	}
</script>
<style>
	@import url("location.css");
</style>